@import '../abstracts/colors.less';
@import '../abstracts/font.less';

// Button: variant mixins

.button-danger() {
  color: var(--btn-text-color);
  background-color: var(--danger);
  border-color: var(--danger);

  &:hover,
  &:focus {
    color: var(--btn-text-color);
    background-color: var(--danger-hover);
    border-color: var(--danger-hover);
  }

  &:active {
    color: var(--btn-text-color);
    background-color: var(--danger-active);
    border-color: var(--danger-active);
  }
}

.button-primary() {
  color: var(--btn-text-color);
  background-color: var(--btn-primary-bg);
  border-color: var(--btn-primary-bg);

  &:hover,
  &:focus {
    color: var(--btn-text-color);
    background-color: var(--btn-primary-bg-hover);
    border-color: var(--btn-primary-bg-hover);
  }

  &:active {
    color: var(--btn-text-color);
    background-color: var(--btn-primary-bg-active);
    border-color: var(--btn-primary-bg-active);
  }
}

.button-secondary() {
  color: var(--btn-secondary-color);
  border-color: var(--btn-secondary-border);
  background-color: var(--btn-secondary-bg);

  &:hover,
  &:focus {
    color: var(--primary-hover);
    border-color: var(--primary-hover);
  }

  &:active {
    color: var(--primary-active);
    border-color: var(--primary-active);
  }
}

.button-link {
  color: var(--primary);
  background-color: transparent;
  border-color: transparent;

  &:hover,
  &:focus {
    color: var(--primary-hover);
    background-color: #f8f8f8;
    border-color: #f8f8f8;
  }

  &:active {
    color: var(--primary-active);
    background-color: #eaeff2;
    border-color: #eaeff2;
  }
}

.button-disabled {
  opacity: 0.5;
  pointer-events: none;
}

// Button styles

.yui-button {
  display: inline-block;
}

.yui-button .first-child {
  display: block;
}

.yui-button button,
input[type="button"],
input[type="reset"],
input[type="submit"],
a.yui-button:link,
a.yui-button:visited {
  box-sizing: border-box;
  display: inline-block;
  // vertical padding:
  // 0.375rem == 6px == 32px (target height) - 4px (borders) - 16 (line) / 2
  padding: 0.375rem 1rem;
  margin-right: 0.25rem;
  margin-left: 0.25rem;
  min-width: 4.5rem;
  min-height: 2rem;

  cursor: pointer;
  user-select: none;
  font-size: var(--font-size-xs);
  line-height: 1rem;
  font-weight: bold;
  text-align: center;
  vertical-align: middle;
  text-decoration: none;

  border: 2px solid;
  border-radius: 4px;

  transition: color 0.15s ease-in-out,
    background-color 0.15s ease-in-out,
    border-color 0.15s ease-in-out;

  .button-secondary();

  &:focus {
    outline: none;
    box-shadow: 0 0 0 0.2rem --var(focus); // TODO come back to this
  }

  display: inline-flex;
  align-items: center;
  justify-content: center;

  & > span {
    display: inline-block;
  }

  .svg-icon,
  i {
    width: 1rem;
    height: 1rem;
    font-size: 1rem;
    vertical-align: top;
    flex-shrink: 1;
  }

  .leading-icon {
    margin-right: 0.25rem;
  }

  .trailing-icon {
    margin-left: 0.25rem;
  }
}

.yui-button.danger button,
input[type="button"].danger,
input[type="reset"].danger,
input[type="submit"].danger {
  .button-danger();
}

.yui-button.primary button,
input[type="button"].primary,
input[type="reset"].primary,
input[type="submit"].primary {
  .button-primary();
}

.yui-button.link-button button,
input[type="button"].link-button,
input[type="reset"].link-button,
input[type="submit"].link-button {
  .button-link();
}

.yui-button.large-button button,
input[type="button"].large-button,
input[type="reset"].large-button,
input[type="submit"].large-button,
a.yui-button.large-button {
  // vertical padding
  // 0.5rem == 8px == 40px (target height) - 4px (borders) - 20 (line) / 2
  padding: 0.5rem 1rem;
  min-width: 6.5rem;
  min-height: 2.5rem;
  font-size: var(--font-size-sm);
  line-height: 1.25rem;

  .svg-icon,
  i {
    vertical-align: top;
    height: 1.25rem;
    width: 1.25rem;
    font-size: 1.25rem;
  }
}

.yui-button-disabled button,
.yui-button button:disabled,
input[type="button"]:disabled,
input[type="reset"]:disabled,
input[type="submit"]:disabled,
.yui-button-disabled input[type="button"],
.yui-button-disabled input[type="reset"],
.yui-button-disabled input[type="submit"] {
  .button-disabled();
}

a.yui-button {
  &.primary {
    .button-primary();
  }

  &.danger {
    .button-danger();
  }

  &.link-button {
    .button-link();
  }

  &.disabled {
    .button-disabled();
  }
}

// Dropdown buttons
.yui-button.yui-menu-button button,
.yui-button.yui-split-button button {
  // These buttons have a caret as the :after element
  &::after {
    display: inline-block;
    margin-left: 0.4em;
    vertical-align: 0.1875em;
    content: "";
    border-top: 0.35em solid;
    border-right: 0.35em solid transparent;
    border-bottom: 0;
    border-left: 0.35em solid transparent;
  }
}
.yui-button.yui-menu-button.yui-menu-button-active button,
.yui-button.yui-split-button.yui-split-button-active button {
  &::after {
    border-bottom: 0.35em solid;
    border-top: 0;
  }
}

// Icon buttons

.yui-button.icon-button button,
a.yui-button.icon-button:link,
a.yui-button.icon-button:visited {
  padding: 0.25rem;
  min-width: 2rem;
  height: 2rem;

  .svg-icon,
  i {
    width: 1rem;
    height: 1rem;
    font-size: 1rem;
  }

  .button-link();
}

.yui-button.icon-button.large-button button,
a.yui-button.icon-button.large-button {
  padding: 0.5rem;
  min-width: 2.5rem;
  height: 2.5rem;
  padding: 0.625rem;

  .svg-icon,
  i {
    width: 1.25rem;
    height: 1.25rem;
    font-size: 1.25rem;
  }
}
